//虚拟订单
var basePage = require('../../../common/BasePage');
var baseList = require('../../../common/BaseList');
var baseOrder = require('../../../common/Order'); 
Page({
    behaviors: [basePage, baseList,baseOrder],
    data: {
        reqUrl: '/home/order/index?type=0&from=virtual',
    },
    onLoad: function (options) {
        this.req_items()
    },
    init_val(val, index, arr) {
        let that=this;
        val.order.order_product.map(function (pdc) {
            pdc.thumb = that.get_thumb(pdc.product_img);
        });
    },
   
     /**跳转支付页面 */
     pay_click(e) {
        //  console.log("pay_click",e);
        wx.navigateTo({
             url: '/pages/integral/my_orderPay/pay',
            success: function (res) {
                // 通过eventChannel向被打开页面传送数据
                res.eventChannel.emit('order', e.currentTarget.dataset.order)
            }
        });
    },
    /**
     * 确认收货
     */
    finished_click(e) {
        console.log("finished_click", e);
        let order = e.currentTarget.dataset.order;
        let index = e.currentTarget.dataset.index;
        let active = this.data.active;
        let that = this;
        wx.showModal({
            title: '提示',
            content: '确认已收到货物？',
            success(res) {
                if (res.confirm) {
                    // console.log('用户点击确定')
                    that.request({
                        url: that.data.host + '/home/order/finished',
                        data: {
                            order_id: order.order_id,
                        },
                        method: "POST",
                    }, res => {
                        if (active != 0) {
                            that.data.itemArr.splice(index, 1);
                        } else {
                            order.order_status = 8;
                            order.order_status_label = "待评价";
                            that.data.itemArr[index] = order;
                        }
                        that.setData({
                            itemArr: that.data.itemArr
                        })
                    })
                } 
            }
        })
    },
    /**
     * 去评价
     */
    comment_click(e){
        let order=e.currentTarget.dataset.order;
        if(order.order.order_product.length>1){
            wx.navigateTo({
                url: '/pages/cls/comment/Order',
                success: function (obj) {
                    //传递订单数据
                  obj.eventChannel.emit('orderData', order)
                }
              })
        }else{
            wx.navigateTo({
                url: '/pages/cls/myOrder_evaluate/evaluate',
                success: function (obj) {
                  //传递产品数据
                  obj.eventChannel.emit('pdcData',order.order.order_product[0])
                }
              })
        }
       
    },
})